package web.exercise.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import web.exercise.Dao.ContactsDao;
import web.exercise.Dao.impl.ContactsDaoImpl;
import web.exercise.entity.Contacts;

public class ModifyServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=utf-8");
		//接收参数，封装对象
		Contacts contacts=new Contacts();
		contacts.setId(request.getParameter("id"));
		contacts.setName(request.getParameter("name"));
		contacts.setAge(request.getParameter("age"));
		contacts.setGender(request.getParameter("gender"));
		contacts.setQQ(request.getParameter("QQ"));
		contacts.setTelephone(request.getParameter("telephone"));
		contacts.setEmail(request.getParameter("email"));
		//传入Dao层写入xml
		ContactsDao dao=new ContactsDaoImpl();
		dao.modify(contacts);
		boolean result=true;
		request.setAttribute("modifyResult", result);
		//请求转发
		request.getRequestDispatcher("ShowListServlet").forward(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
}
